import 'package:flutter/material.dart';
import 'package:flutter_yn_goods/config/app_color.dart';
import 'package:flutter_yn_goods/config/app_translations.dart';
import 'package:flutter_yn_goods/utils/address_service.dart';
import 'package:flutter_yn_goods/widgets/appbar/common_app_bar.dart';
import 'package:flutter_yn_goods/widgets/button/common_button.dart';
import 'package:flutter_yn_goods/widgets/login_input_item_view.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'modify_address_logic.dart';

class ModifyAddressPage extends StatelessWidget {
  ModifyAddressPage({Key? key}) : super(key: key);

  final ModifyAddressLogic logic = Get.put(ModifyAddressLogic());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ModifyAddressLogic>(builder: (logic) {
      return Scaffold(
        appBar: CommonAppBar(
          title:  LocaleKeys.edit_address.tr,
        ),
        body: Column(
          children: [
            // 16.verticalSpaceFromWidth,
            // _buildSelect( LocaleKeys.delivery_address.tr,
            //     hintText:  LocaleKeys.please_select_address.tr,
            //     isRequired: true,
            //     content: logic.cityName, onClick: () {
            //       AddressService.showVietnamAddressPicker((address, value) {
            //         // clog('dalskdjlksa   $value');
            //         // [].;
            //         logic.cityName = address.join('-');
            //
            //         logic.province = value[0].toString();
            //         logic.city = value[1].toString();
            //         logic.area = value[2].toString();
            //         logic.onTextChanged();
            //         logic.update();
            //         // [].join('-');
            //         // [].s
            //       });
            //     }),
            16.verticalSpaceFromWidth,
            LoginInputItemView(
              title: LocaleKeys.address_detail.tr,
              margin: EdgeInsets.symmetric(horizontal: 16.w),
              textEditingController: logic.textEditingController,
              maxLength: 32,
              isRequired: true,
              hintText: LocaleKeys.please_enter_address_detail.tr,
              // errorText: logic.phoneErrorText.value,
              textChanged: (v) {
                logic.onTextChanged();
                // logic.registerModelRx.value.address = v;
                // logic.onAccountTextChange();
              },
            ),
            44.verticalSpaceFromWidth,
            Padding(
              padding: EdgeInsets.symmetric(horizontal: 22.w),
              child: Obx(() {
                return CommonButton.expend(
                  title: LocaleKeys.save.tr,
                  height: 44.w,
                  enable: logic.buttonEnable.value,
                  disableTextColor: AppColor.color86888F,
                  disableBackgroundColor: Colors.black.withOpacity(0.1),
                  onClick: () {
                    logic.saveAddress();
                  },
                );
              }),
            ),
          ],
        ),

      );
    });
  }

  InputBorder get noneBorder {
    return const OutlineInputBorder(
      borderSide: BorderSide.none,
    );
  }

  Widget _buildSelect(String title,
      {bool isRequired = false,
      String? content,
      required String hintText,
      required Function onClick}) {
    return GestureDetector(
      onTap: () {
        onClick.call();
      },
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 16.w),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Text(
                  title,
                  style: TextStyle(
                      color: AppColor.color282828,
                      fontSize: 12.sp,
                      fontWeight: FontWeight.w600),
                ),
                4.horizontalSpace,
                Visibility(
                    visible: isRequired,
                    child: Text(
                      '*',
                      style: TextStyle(
                          color: AppColor.primary,
                          fontSize: 12.sp,
                          fontWeight: FontWeight.w600),
                    ))
              ],
            ),
            12.verticalSpaceFromWidth,
            Container(
                height: 52.w,
                decoration: BoxDecoration(
                  color: AppColor.colorF5F5F5,
                  borderRadius: BorderRadius.circular(12.w),
                ),
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.symmetric(horizontal: 16.w),
                child: Row(
                  children: [
                    Expanded(
                        child: Text(
                            (content ?? '').isNotEmpty
                                ? (content ?? '')
                                : hintText,
                            style: (content ?? '').isNotEmpty
                                ? TextStyle(
                                    color: AppColor.color282828,
                                    fontSize: 14.sp,
                                    fontWeight: FontWeight.w500)
                                : TextStyle(
                                    color: AppColor.color999999,
                                    fontSize: 14.sp,
                                    fontWeight: FontWeight.w400))),
                    const Icon(
                      Icons.arrow_forward_ios,
                      size: 16,
                      color: AppColor.color999999,
                    )
                  ],
                ))
          ],
        ),
      ),
    );
  }
}
